//	Temporary rewrite of C&EN Homepage search box . Remove once included in main.js:
/* for search box on C&EN Archives home page */
function cenArchiveSearch() {
    var select = $('cenArchSearchArea');
    var searchArea = select.options[select.selectedIndex].value;
    var searchString = $('cenArchSearchString').value;

    if (searchString == "") {
        alert('Please enter search terms before running your search.');
        return false;
    }
    var cenSearchInput = $('cenSimpleSearchArea');
    cenSearchInput.name = searchArea;
    cenSearchInput.value = searchString;
    $('cenArchSearch').submit();
}

//	Code to try running at document load. These must test to see whether they are appropriate for the given page.
document.observe("dom:loaded", function() {
	//	Dynamically add the Website Demos button to the profile bar
	if ($('profile')) {
		var target = $('profile').getElementsByTagName('div')[0];
		var content = '  <a style="color: #fff; background: #ec8440; border: 1px solid #da6619; padding: 1px 3px; text-decoration: none; margin-left: 7px;" href="/page/demo/index.html">Website Demos</a>';
		$(target).insert({bottom: content});
	}
	
	//	Find and parse JW Player parameters from #jwPlayerContainer if present
	jwPlayerParams = $$('div#jwPlayerContainer > form > input');
	if (jwPlayerParams.length) {
		jwBuilder = new JWPlayerBuilder(jwPlayerParams);
		jwBuilder.loadSWFs();
	}
});

function pubsLogin() {
	if (window.signIn) {
		alert ('On this page, please use the Log In box that appears in the yellow box below the article title. Thank you.');
		new Effect.ScrollTo('articleMain');
		return false;
	}
	var bg = '<div id="bgWhite" style="display:none;">&nbsp;<\/div>';
	$('container').insert(bg);
	$('bgWhite').appear({to:0.85});
	$('loginLayer-wrap').appear();
	if ($('loginLoadMsg')) $('loginLoadMsg').remove();
	$('layerLogin').appear({afterFinish: function(){$('acsID').focus();}});
	// make it so clicking outside of the layer hides the layer
	setTimeout(function(){Event.observe(document,"click",closeLoginBox);},100);
}